﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace assim
{

    class Assembler
    {
        class Instruction
        {
            string name;
            int code;
            static int count = 0;

            public Instruction(string _name)
            {
                name = _name;
                code = count++;
            }
        }

        static Instruction[] instructions = 
        {
            new Instruction("add"),
            new Instruction("sub"),
            new Instruction("and"),
            new Instruction("or"),
            new Instruction("nor"),
            new Instruction("sll"),
            new Instruction("srl"),
            new Instruction("slt"),
            new Instruction("sgt"),
            new Instruction("seq"),
            new Instruction("inc"),
            new Instruction("dec"),
            new Instruction("addi"),
            new Instruction("subi"),
            new Instruction("andi"),
            new Instruction("ori"),
            new Instruction("nori"),
            new Instruction("slti"),
            new Instruction("sgti"),
            new Instruction("segi"),
            new Instruction("lbu"),
            new Instruction("lhu"),
            new Instruction("lw"),
            new Instruction("lui"),
            new Instruction("sb"),
            new Instruction("sh"),
            new Instruction("sw")
        };

        public static bool AssembleCode(string code, List<int> data)
        {
            List<string> lines = GetLines(code);

            char[] separators = { '\t', ' ', ',' };
            for(int i = 0; i < lines.Count; i++)
            {
                string[] tokens = lines[i].Split(separators);
                for(int j = 0; j < tokens.Length; j++)
                    ;
            }

            return true;
        }

        private static List<string> GetLines(string code)
        {
            char[] separators = {'\n'};
            string[] lines = code.Split(separators);

            List<string> _lines = new List<string>();

            for(int i = 0; i < lines.Length; i++)
                if(lines[i].Length > 2 && lines[i][0] != '#')
                    _lines.Add(lines[i]);

            return _lines;
        }
    }
}
